/*
 * Copyright (c) 2014, 2015, XIANDIAN and/or its affiliates. All rights reserved.
 * XIANDIAN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 */
package com.xiandian.cloud.storage.fragment;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.woorea.openstack.keystone.model.Tenant;
import com.woorea.openstack.swift.Swift;
import com.woorea.openstack.swift.api.ContainerResource;
import com.woorea.openstack.swift.model.Container;
import com.woorea.openstack.swift.model.Object;
import com.woorea.openstack.swift.model.ObjectDownload;
import com.woorea.openstack.swift.model.ObjectForUpload;
import com.woorea.openstack.swift.model.Objects;
import com.xiandian.cloud.storage.ObjectListActivity;
import com.xiandian.cloud.storage.R;
import com.xiandian.cloud.storage.base.OpenstackApplicationState;
import com.xiandian.cloud.storage.base.TaskResult;
import com.xiandian.cloud.storage.object.PseudoFileSystem;
import com.xiandian.cloud.storage.sdk.service.OpenStackClientService;
import com.xiandian.cloud.storage.signup.LoginActivity;
import com.xiandian.cloud.storage.utils.DisplayUtils;
import com.xiandian.cloud.storage.utils.GraphicsUtil;
import com.xiandian.cloud.storage.utils.PromptDialogUtil;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

/**
 * 回收站
 * @author 云计算应用与开发项目组
 * @since  V1.0
 */
public class RecycleObjectListFragment extends Fragment {
	ListView list_root;
	SwipeRefreshLayout swipe_refresh_files;
	List<PseudoFileSystem> listPseudoFileSystem;
	List<Object> listObjects;
	
	String mCurrentPhotoPath;
	Uri mImageUri = null;
	
	String containerName;
	Context context;
	
	public RecycleObjectListFragment(Context _context){
		this.context=_context;
		
		containerName="garbage_"+getApplicationState().getSelectedContainer().getName();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_object_list,
				container, false);
		
		setHasOptionsMenu(true);
		
		list_root=(ListView) rootView.findViewById(R.id.list_root);
		list_root.setOnItemLongClickListener(new OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View view,
					int position, long id) {
				
				return true;
			}
		});
		
		swipe_refresh_files=(SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_files);
		swipe_refresh_files.setColorSchemeColors(0,0,0,0);
		swipe_refresh_files.setOnRefreshListener(new OnRefreshListener() {

			@Override
			public void onRefresh() {
				swipe_refresh_files.setRefreshing(false);
				getActivity().setProgressBarIndeterminateVisibility(true);
				
			}
		});

		getApplicationState().setSelectedDirectory(null);
		
		return rootView;
	}
	
	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
		// TODO Auto-generated method stub
		inflater.inflate(R.menu.recycle, menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		int id = item.getItemId();
		switch (id) {
		case R.id.action_clear:
			
			break;

		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	/**
	 * Clean name.
	 * 
	 * @param objectName
	 *            the object name
	 * @return the string
	 */
	private String cleanName(String objectName) {
		String[] parts = objectName.split("/");
		return parts[parts.length - 1];
	}

	private OpenstackApplicationState getApplicationState(){
		return OpenstackApplicationState.getInstance();
	}

	private OpenStackClientService getService(){
		return OpenStackClientService.getInstance();
	}

}
